use fql_server::{curd_implement, App};
use nickel::{Nickel, Options};

// cargo run examples
fn main() {
    let app = App::parse_env();
    let mut server = Nickel::new();

    prepare_work(&app, &mut server);
    curd_implement(&app, &mut server);
    server.listen(app.localhost()).unwrap();
}

/// 准备工作
pub fn prepare_work(app: &crate::App, server: &mut nickel::Nickel) {
    println!(
        r"
        ________ ________  ___       ________  _______   ________  ___      ___ _______   ________     
        |\  _____\\   __  \|\  \     |\   ____\|\  ___ \ |\   __  \|\  \    /  /|\  ___ \ |\   __  \    
        \ \  \__/\ \  \|\  \ \  \    \ \  \___|\ \   __/|\ \  \|\  \ \  \  /  / | \   __/|\ \  \|\  \   
         \ \   __\\ \  \\\  \ \  \    \ \_____  \ \  \_|/_\ \   _  _\ \  \/  / / \ \  \_|/_\ \   _  _\  
          \ \  \_| \ \  \\\  \ \  \____\|____|\  \ \  \_|\ \ \  \\  \\ \    / /   \ \  \_|\ \ \  \\  \| 
           \ \__\   \ \_____  \ \_______\____\_\  \ \_______\ \__\\ _\\ \__/ /     \ \_______\ \__\\ _\ 
            \|__|    \|___| \__\|_______|\_________\|_______|\|__|\|__|\|__|/       \|_______|\|__|\|__|
                           \|__|        \|_________|                                                    
"
    );
    println!("FQLServer is running at http://{}", app.localhost());
    server.options = Options::default().output_on_listen(false);
}
